package cn.com.bob.messageboard.utils;

import java.util.Random;
import java.util.UUID;

/**
 * @Author Bob
 * @Version：1.0
 */
public class VerificationCodeUtil {
    public static String generateVerificationCode(int length) {
        // 可选的字符集合，这里选择数字和大写字母
        String charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        StringBuilder code = new StringBuilder(length);

        Random random = new Random();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(charset.length());
            code.append(charset.charAt(index));
        }

        return code.toString();
    }

    public static String generateToken() {
        // 使用UUID类生成随机的Token值
        UUID uuid = UUID.randomUUID();

        // 将UUID转换为字符串并去掉横杠
        String token = uuid.toString().replace("-", "");

        // 返回生成的Token值
        return token;
    }
}
